#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
#include <stack>
#include <string>
#include <vector>
#include <queue>
using namespace std;

struct TreeNode {
    int val;
    TreeNode* left;
    TreeNode* right;
    TreeNode() : val(0), left(nullptr), right(nullptr) {}
    TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
    TreeNode(int x, TreeNode* left, TreeNode* right) : val(x), left(left), right(right) {}
};

class Solution {
public:
    vector<vector<int>> levelOrderBottom(TreeNode* root) {
        vector<vector<int>> ret;
        if (root == nullptr)
            return ret;
        queue<TreeNode*> st;
        st.push(root);
        while (!st.empty())
        {
            int n = st.size();
            vector<int> tmp;
            while (n--)
            {
                TreeNode* temp = st.front();
                st.pop();
                tmp.push_back(temp->val);
                if (temp->left)
                    st.push(temp->left);
                if (temp->right)
                    st.push(temp->right);
            }
            ret.push_back(tmp);
        }
        vector<vector<int>> result;
        for (int i = ret.size() - 1; i >= 0; i--)
        {
            result.push_back(ret[i]);
        }
        return result;
    }
};

int main()
{
	return 0;
}
